//package iie.cas.securedemo;
//
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.security.*;
//import java.security.cert.CertificateException;
//import java.security.spec.X509EncodedKeySpec;
//
//public class CaTest {
//
//    public static void main(String[] args) throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
//        // 初始化KeyPairGenerator
//        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
//        keyPairGenerator.initialize(2048);
//
//        // 生成一对公钥和私钥
//        KeyPair keyPair = keyPairGenerator.generateKeyPair();
//
//        // 将公钥保存为证书文件
//        PublicKey publicKey = keyPair.getPublic();
//        X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
//        FileOutputStream fos = new FileOutputStream("C:\\publicKey.cer");
//        fos.write(x509EncodedKeySpec.getEncoded());
//        fos.close();
//
//        // 将私钥和证书文件合并为keystore文件
//        KeyStore keyStore = KeyStore.getInstance("PKCS12");
//        keyStore.load(null, null);
//        keyStore.setKeyEntry("keyAlias", keyPair.getPrivate(), "keyPassword".toCharArray(), new Certificate[]{});
//
//        // 导出keystore文件为p12文件
//        FileOutputStream p12Out = new FileOutputStream("C:\\keystore.p12");
//        keyStore.store(p12Out, "p12Password".toCharArray());
//        p12Out.close();
//    }
//
//}
